package com.hlx.service.user.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.hlx.entity.user.OrderForm;
import com.hlx.mapper.user.OrderMapper;
import com.hlx.service.user.OrderFormService;
import com.hlx.utils.OrderNoCreate;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class OrderFormServiceImpl extends ServiceImpl<OrderMapper, OrderForm> implements OrderFormService {
    @Override
    public boolean addOrder(Integer ticketId) {
        OrderForm order = new OrderForm();
        OrderNoCreate orderNo = new OrderNoCreate();
        order.setOrderNumber(orderNo.getOrderNumber());
        order.setTicketId(ticketId);
        order.setOrderStatus(0);
        if(this.save(order)) {
            return true;
        }
        return false;
    }

    @Override
    public List<OrderForm> getOrderForm(List<Integer> ticketId) {
        LambdaQueryWrapper<OrderForm> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.in(OrderForm::getTicketId,ticketId);
        List<OrderForm> orderForms = this.list(queryWrapper);
        if (orderForms.isEmpty()){
            return null;
        }
        return orderForms;
    }

    @Override
    public boolean deleteOrder(Integer ticketId) {
        LambdaQueryWrapper<OrderForm> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.in(OrderForm::getTicketId,ticketId);
        return this.remove(queryWrapper);
    }

    @Override
    public boolean deleteOrderByTicketIds(List<Integer> ticketIds) {
        LambdaQueryWrapper<OrderForm> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.in(OrderForm::getTicketId,ticketIds);
        return this.remove(queryWrapper);
    }
}
